
$file1 = "all_ambi";
$file2 = "fwdStrandResults_new_mayogap_emerge_clean.tped";
$file3 = "excluded_heu_obs";
chomp $file1;
chomp $file2;
open(WRBUFF,">excl_hapmap_ambi_fwdStrandResults_new_mayogap_emerge_clean.tped");
open(WRBUFF1,">ambi_fwdStrandResults_new_mayogap_emerge_clean.tped");
open(WRBUFF2,">nothapmap_sample_snps_fwdStrandResults_new_mayogap_emerge_clean.tped");
open(BUFF1,$file1);
open(BUFF2,$file2);
open(BUFF3,$file3);
while($line = <BUFF1>)
{
	chomp $line;
	$line =~ s/\n//g;
	$line =~ s/\r//g;
	$line =~ s/\t//g;
	$line =~ s/\s//g;	
	$hash1{$line} = 1;
}
while($line = <BUFF3>)
{
        chomp $line;
        $line =~ s/\n//g;
        $line =~ s/\r//g;
        $line =~ s/\t//g;
        $line =~ s/\s//g;
        $hash2{$line} = 2;
}
while($line = <BUFF2>)
{
	chomp $line;
        $line =~ s/\n//g;
        $line =~ s/\r//g;
        #$line =~ s/\t//g;
        #$line =~ s/\s//g;
	@array = split(" ",$line);
	
	$array[1] =~ s/\n//g;
	$array[1] =~ s/\r//g;
	$array[1] =~ s/\t//g;
	$array[1] =~ s/\s//g;
	#print $array[1]."\n";
	if($hash2{$array[1]} == 2)
	{
		print WRBUFF2 $line."\n";
	}
        elsif($hash1{$array[1]} == 1 )
	{
		print WRBUFF1 $line."\n";
	#	for($i=4;$i<@array;$i++)
	#	{
	#		$array[$i] = 0;
	#	}
	#	$line = join(" ",@array);
	#	print WRBUFF $line."\n";
	}
	else{ 
		 print WRBUFF $line."\n"; 
	}
}


